using System;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;

namespace HengTong.Model.Db.System;

/// <summary>
/// 编码规则配置表
/// </summary>
public class SysCodeRule : TopBasePoco, ITenant
{
    [Display(Name = "编码名称", Description = "编码规则的名称", GroupName = "基本信息")]
    [Required(ErrorMessage = "请输入编码名称")]
    [MaxLength(128)]
    public string Name { get; set; }

    [Display(Name = "编码类型", Description = "业务单据类型（使用模型名称）", GroupName = "基本信息")]
    [Required(ErrorMessage = "请输入编码类型")]
    [MaxLength(128)]
    public string CodeType { get; set; }

    [Display(Name = "编码前缀", Description = "编码的固定前缀", GroupName = "编码规则")]
    [MaxLength(16)]
    public string Prefix { get; set; }

    [Display(Name = "日期格式", Description = "编码中的日期格式，如：yyyyMMdd、yyyyMM等", GroupName = "编码规则")]
    [MaxLength(16)]
    public string DateFormat { get; set; }

    [Display(Name = "序号长度", Description = "序号部分的位数", GroupName = "编码规则")]
    [Range(1, 10, ErrorMessage = "序号长度必须在1-10位之间")]
    public int SerialLength { get; set; } = 4;

    [Display(Name = "编码后缀", Description = "编码的固定后缀", GroupName = "编码规则")]
    [MaxLength(16)]
    public string Suffix { get; set; }

    [Display(Name = "重置规则", Description = "序号重置规则", GroupName = "编码规则")]
    public CodeResetRule ResetRule { get; set; } = CodeResetRule.Yearly;

    [Display(Name = "当前序号", Description = "当前的序号值", GroupName = "状态信息")]
    public int CurrentSerial { get; set; } = 0;

    [Display(Name = "最后生成时间", Description = "最后一次生成编码的时间", GroupName = "状态信息")]
    public DateTime? LastGenerateTime { get; set; }

    [Display(Name = "最后重置时间", Description = "最后一次重置序号的时间", GroupName = "状态信息")]
    public DateTime? LastResetTime { get; set; }

    [Display(Name = "是否启用", Description = "是否启用此编码规则", GroupName = "状态信息")]
    public bool IsEnabled { get; set; } = true;

    [Display(Name = "排序", Description = "显示排序", GroupName = "状态信息")]
    public int Sort { get; set; } = 0;

    [Display(Name = "备注", Description = "备注信息", GroupName = "其他")]
    [MaxLength(256)]
    public string Remark { get; set; }

    [Display(Name = "租户代码", Description = "多租户系统中的租户唯一标识", GroupName = "系统设置")]
    [MaxLength(128)]
    public string TenantCode { get; set; }
}
